package com.qf.mrmd.service.impl;

import com.qf.mrmd.entity.Subject;
import com.qf.mrmd.dao.SubjectDao;
import com.qf.mrmd.result.ResponseCode;
import com.qf.mrmd.result.ResponseData;
import com.qf.mrmd.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Subject)表服务实现类
 *
 * @author makejava
 * @since 2021-07-14 14:39:49
 */
@Service("subjectService")
public class SubjectServiceImpl implements SubjectService {

    @Resource
    private SubjectDao subjectDao;

    /**
     * 通过ID查询单条数据
     *
     * @param suId 主键
     * @return 实例对象
     */
    @Override
    public ResponseData queryById(Integer suId) {
        Subject subject = subjectDao.queryById(suId);
        if(subject == null){
            return new ResponseData("401","服务不存在",null);
        }
        return new ResponseData(ResponseCode.SUCCESS,subject);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<Subject> queryAllByLimit(int offset, int limit) {
        return this.subjectDao.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param subject 实例对象
     * @return 实例对象
     */
    @Override
    public Subject insert(Subject subject) {
        this.subjectDao.insert(subject);
        return subject;
    }

    /**
     * 修改数据
     *
     * @param subject 实例对象
     * @return 实例对象
     */
    @Override
    public Subject update(Subject subject) {
        this.subjectDao.update(subject);
        return null;
    }

    /**
     * 通过主键删除数据
     *
     * @param suId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer suId) {
        return this.subjectDao.deleteById(suId) > 0;
    }

    @Override
    public ResponseData queryByTitle(String title) {
//        完成当前业务逻辑判定
        List<Subject> subjectList= subjectDao.queryByTitle(title);
        return new ResponseData(ResponseCode.SUCCESS,subjectList);
    }
}
